package logic

import (
	"context"
	"grpc.getaway.adminspro.padmins.com/internal/rpc/utils/database"
	"grpc.getaway.adminspro.padmins.com/pkg/config/businessError"
)

func GetResourceIdsByAdminId(ctx context.Context, adminId int64) ([]int64, *businessError.ErrorInfo) {
	rows, e := database.Db.GetDefaultDb(ctx).Query("select agra.resource_id from admin_role_access aga "+
		"join admin_role_resource_access agra on aga.role_id=agra.role_id where aga.admin_id=?", adminId)

	if e != nil {
		return nil, businessError.DbError(e)
	}

	data := make([]int64, len(rows))

	for i, row := range rows {
		data[i] = row["resource_id"].(int64)
	}

	return data, nil
}
